package com.ars.common.servlet.admin;

import com.ars.common.dao.permission.UserInformationSet;
import com.ars.common.beans.User.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.time.Year;
import java.util.ArrayList;

@WebServlet("/UserPermissionSettingsServlet")
public class UserPermissionSettingsServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response); // 复用处理逻辑
    }

    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String year = request.getParameter("id");
        year = String.valueOf(Year.now().getValue() + 1 - Integer.parseInt(year));//获取当前年份
        System.out.println(year);

        User user = (User) request.getSession().getAttribute("LogUser");
        String userID = user.getUserID();
        String collegeID =year + userID.substring(4, 6);
        System.out.println(collegeID);

        try {
            ArrayList<User> userInfo= UserInformationSet.getUserInfo(collegeID);
            request.setAttribute("userInfo", userInfo);
            request.getRequestDispatcher("/admin/userPermissionSettings.jsp").forward(request, response);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }


    }
}
